class Solution {
    vector<string> split(const string& s, char delim)
    {
        vector<string> res;
        stringstream ss(s);
        string token;
        while (getline(ss, token, delim))
        {
            res.push_back(token);
        }
        return res;
    }

public:
    int compareVersion(string version1, string version2) {
        auto a = split(version1, '.');
        auto b = split(version2, '.');
        int n = a.size(), m = b.size();
        for (int i = 0; i < n || i < m; i++)
        {
            int ver1 = i < n ? stoi(a[i]) : 0;
            int ver2 = i < m ? stoi(b[i]) : 0;
            if (ver1 != ver2)
            {
                return ver1 < ver2 ? -1 : 1;
            }
        }
        return 0;
    }
};